package rjgc.mall.controller;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rjgc.mall.common.Result;
import rjgc.mall.entity.Address;
import rjgc.mall.service.AddressService;

import java.util.List;


@RestController
@RequestMapping("/Address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    //添加地址
    @RequestMapping("/addAddress")
    public Result AddAddress(String address,Integer userid){
        addressService.addAddress(address,userid);
        return new Result(true,"添加成功");
    }
    //删除地址
    @DeleteMapping("deleteAddress")
    public Result DeleteArea(Integer id){
        addressService.deleteAddress(id);
        return new Result(true,"删除成功");
    }
    //设定默认地址
    @RequestMapping("/setAddress")
    public Result SetArea(Integer id,Integer userid){
        addressService.setAddress(id,userid);
        return new Result(true,"设置成功");
    }
    //展示用户所有地址
    @RequestMapping("/showAddressByUserId")
    public List<Address> ShowAreaByUserId(Integer userid){
        return addressService.showAddressByUserId(userid);
    }

    //获取用户默认地址
    @RequestMapping("showUserSelectAddress")
    public String ShowUserSelectAddress(Integer userid){
        Address address = addressService.showUserSelectAddress(userid);
        return address.getAddress();
    }
}
